package by.grsu.as.tools;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import by.grsu.as.dao.DaoAdmin;
import by.grsu.as.dao.DaoCar;
import by.grsu.as.dao.DaoClient;
import by.grsu.as.dao.DaoZayava;
import by.grsu.as.model.Admin;
import by.grsu.as.model.Client;
import by.grsu.as.model.Car;
import by.grsu.as.model.Zayava;

import com.epam.grsulab.webapi.dao.base.Dao;
import com.epam.grsulab.webapi.entity.base.BaseEntity;
import com.epam.grsulab.webapi.tools.DataInitialiser;

@Component
public class UnionImpl implements DataInitialiser {

	private static final Logger logger = LoggerFactory
			.getLogger(UnionImpl.class);

	@Autowired
	private DaoAdmin adminDao;
	@Autowired
	private DaoCar carDao;
	@Autowired
	private DaoClient clientDao;
	@Autowired
	private DaoZayava zayavaDao;

	@Override
	public void initData() {
		Admin admin = new Admin();
		admin.setLastname("Semenov");
		admin.setName("Arkadiy");
		admin = adminDao.save(admin);

		Car car = new Car();
		car.setColor("black");
		car.setKoeff(15);
		car.setName("BMW");
		car.setVolume(2500);
		car = carDao.save(car);
		
		Client client = new Client();
		client.setAge(20);
		client.setDays(14);
		client.setLastname("Sakuta");
		client.setName("Dmitry");
		client = clientDao.save(client);

		Zayava zayavaEntity = new Zayava();
		zayavaEntity.setAdmin(admin);
		zayavaEntity.setCar(car);
		zayavaEntity.setClient(client);
		zayavaEntity = zayavaDao.save(zayavaEntity);

	}

	@Override
	public List<Dao<? extends BaseEntity>> getAllDAOs() {
		List<Dao<? extends BaseEntity>> list = new ArrayList<Dao<? extends BaseEntity>>();

		list.add(adminDao);
		list.add(carDao);
		list.add(clientDao);
		list.add(zayavaDao);

		return list;
	}

}
